const routes = [
  //配置路由
  {
    path: "/",
    redirect: "/home",
    meta: { show: true },
  },
  {
    path: "/login",
    name: "login",
    component: () => import("@/pages/Login/index.vue"),
    meta: { show: false },
  },
  {
    path: "/register",
    name: "register",
    component: () => import("@/pages/Register/index.vue"),
    meta: { show: false },
  },
  {
    path: "/home",
    name: "home",
    component: () => import("@/pages/Home/index.vue"),
    meta: { show: true },
  },
  {
    //params传参数
    path: "/search/:keyword?",
    name: "search",
    component: () => import("@/pages/Search/index.vue"),
    meta: { show: true },
  },
  {
    //params传参数
    path: "/detail/:skuId",
    name: "detail",
    component: () => import("@/pages/Detail/index.vue"),
    meta: { show: true },
  },
  //AddCartSuccess
  {
    //params传参数
    path: "/addcartsuccess",
    name: "addCartSuccess",
    component: () => import("@/pages/AddCartSuccess/index.vue"),
    meta: { show: true },
  },
  {
    path: "/shopcart",
    name: "shopCart",
    meta: { show: true },
    component: () => import("@/pages/ShopCart/index.vue"),
  },
  //TODO
  {
    path: "/trade",
    name: "Trade",
    meta: { show: true },
    component: () => import("@/pages/Trade/index.vue"),
    beforeEnter: (to, from, next) => {
      console.log("From path:", from.path);
      if (from.path === "/shopcart") {
        next();
      } else {
        console.log("Navigation blocked.");
        next(false);
      }
    },
  },
  {
    path: "/pay",
    name: "Pay",
    meta: { show: true },
    component: () => import("@/pages/Pay/index.vue"),
    beforeEnter: (to, from, next) => {
      if (from.path === "/trade") {
        next();
      } else {
        next(false);
      }
    },
  },
  {
    path: "/paysuccess",
    name: "Paysuccess",
    meta: { show: true },
    component: () => import("@/pages/PaySuccess/index.vue"),
  },
  {
    path: "/center",
    name: "Center",
    meta: { show: true },
    component: () => import("@/pages/Center/index.vue"),
    children: [
      { path: "/center", redirect: "/center/myorder" },
      {
        path: "myorder",
        name: "MyOrder",
        component: () => import("@/pages/Center/myOrder/index.vue"),
      },
      {
        path: "/grouporder",
        name: "GoupOrder",
        component: () => import("@/pages/Center/groupOrder/index.vue"),
      },
    ],
  },
];
export default routes;
